import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:dk_flutter_base/dk_ui.dart';
import 'package:flutter_dk_form/flutter_dk_form.dart';

class PageDialogDemoWidget extends StatefulWidget {
  static const String routeName = '/page/dialog_demo_page';
  static const String name = "Dialog Demo";
  final btnData = ['内容+两个按钮', '内容+一个按钮', '底部弹出（内容随便放）', '无按钮', '内容展示弹框'];

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return PageDialogDemoWidgetState();
  }
}

class PageDialogDemoWidgetState extends State<PageDialogDemoWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Dialog Demo")),
      body: ListView.builder(
          itemCount: widget.btnData.length,
          itemBuilder: (context, index) {
            return InkWell(
              onTap: () {
                if (index == 0) {
                  alertDialogTwoBtnWithDivider();
                } else if (index == 1) {
                  alertDialogOneBtnWithDivider();
                } else if (index == 2) {
                  dialogWithGravity(context, gravity: Gravity.bottom);
                } else if (index == 3) {
                  alertDialog();
                } else if (index == 4) {
                  alertDialogOneBtnContentWithDivider();
                }
              },
              child: new Card(
                child: new Container(
                  alignment: Alignment.centerLeft,
                  margin: EdgeInsets.symmetric(horizontal: 10),
                  height: 50,
                  child: new Text(widget.btnData[index]),
                ),
              ),
            );
          }),
    );
  }

  DkDialog dialogWithGravity(BuildContext context,
      {double width, gravity, doubleButtonGravity}) {
    return DkDialog().build(context)
      ..width = width
      ..gravity = gravity
      ..gravityAnimationEnable = true
      ..borderRadius = 4.0
      ..closeButton(
          paddingTop: 5,
          paddingRight: 5,
          onTap: () {
            print("关闭");
          })
      ..text(
        padding: EdgeInsets.all(18.0),
        text: "Use location service?",
        color: Colors.black,
        fontSize: 18.0,
        fontWeight: FontWeight.w500,
      )
      ..text(
        padding: EdgeInsets.only(left: 18.0, right: 18.0),
        text:
            "Let us help apps determine location. This means sending anonymous location data to us, even when no apps are running.",
        color: Colors.grey[500],
        fontSize: 15.0,
      )
      ..widget(
        Image(image: NetworkImage("http://172.18.130.18/favicon.ico")),
      )
      ..doubleButton(
        padding: EdgeInsets.only(top: 20.0),
        text1: "DISAGREE",
        color1: Colors.deepPurpleAccent,
        fontSize1: 14.0,
        text2: "AGREE",
        color2: Colors.deepPurpleAccent,
        fontSize2: 14.0,
      )
      ..show();
  }

  DkDialog alertDialogOneBtnWithDivider() {
    return DkDialog().build(context)
      ..width = 300
      ..borderRadius = 10
      ..text(
        padding: EdgeInsets.all(25.0),
        textAlign: TextAlign.center,
        text: "是否将银行储蓄卡：6217********5656356作为“代扣缴服务”专用卡",
        color: Color(0xFF666666),
        fontSize: 18.0,
      )
      ..divider(color: Color(0xFFEBEBEB), height: 0.5)
      ..oneButton(
        padding: EdgeInsets.only(top: 10.0),
        gravity: Gravity.center,
        text: "确定",
        color: Color(0xFF3DBCC6),
        fontSize: 17.0,
        fontWeight: FontWeight.bold,
        onTap: () {
          print("确定");
        },
      )
      ..show();
  }

  DkDialog alertDialogTwoBtnWithDivider() {
    return DkDialog().build(context)
      ..width = 300
      ..borderRadius = 10
      ..text(
        padding: EdgeInsets.all(25.0),
        textAlign: TextAlign.center,
        text: "是否将银行储蓄卡：6217********5656356作为“代扣缴服务”专用卡",
        color: Color(0xFF666666),
        fontSize: 18.0,
      )
      ..divider(color: Color(0xFFEBEBEB), height: 0.5)
      ..doubleButton(
        padding: EdgeInsets.only(top: 10.0),
        gravity: Gravity.center,
        withDivider: true,
        text1: "取消",
        color1: Color(0xFF666666),
        fontSize1: 17.0,
        fontWeight1: FontWeight.bold,
        onTap1: () {
          print("取消");
        },
        text2: "确定",
        color2: Color(0xFF3DBCC6),
        fontSize2: 17.0,
        fontWeight2: FontWeight.bold,
        onTap2: () {
          print("确定");
        },
      )
      ..show();
  }

  DkDialog alertDialog() {
    return DkDialog().build(context)
      ..width = 300
      ..borderRadius = 10
      ..text(
        padding: EdgeInsets.all(25.0),
        textAlign: TextAlign.center,
        text: "是否将银行储蓄卡：6217********5656356作为“代扣缴服务”专用卡",
        color: Color(0xFF666666),
        fontSize: 18.0,
      )
      ..show();
  }

  DkDialog alertDialogOneBtnContentWithDivider() {
    return DkDialog().build(context)
      ..width = 300
      ..borderRadius = 10
      ..text(
        padding: EdgeInsets.only(top: 40, bottom: 3),
        textAlign: TextAlign.center,
        alignment: Alignment.center,
        text: "委托扣款协议书",
        color: Color(0xFF000000),
        fontSize: 16.0,
      )
      ..text(
        height: 324,
        padding: EdgeInsets.all(25.0),
        textAlign: TextAlign.center,
        text:
            "啦房间需要新建墙的情况可使用此包，文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文字编辑文字编辑文文字编辑文辑文字编辑文文字编辑文辑文字编辑文文字文字编辑文文字编辑文辑文字编辑文文字11111",
        color: Color(0xFF333333),
        fontSize: 14.0,
      )
      ..radioButton(
        height: 36,
        margin: EdgeInsets.only(bottom: 30),
        padding: EdgeInsets.only(left: 42, right: 42, top: 8, bottom: 8),
        borderRadius: BorderRadius.all(
          Radius.circular(18),
        ),
        text: "我知道了",
        color: Color(0xFF3DBCC6),
        fontSize: 14.0,
        onTap: () {
          print("我知道了");
        },
        border: Border.all(color: Color(0xFFE4E8EB), width: 1),
      )
      ..show();
  }
}
